package org.jvnet.hudson.client_demo;

import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class QueryJobs {

	public static void main(String[] args) throws Exception {
		
		
		
		String urlStr = "http://10.144.97.100:8080/jenkins/api/xml";
        
        Map<String,Object> map = new HashMap<String,Object>();
        InputStream res = null ;
        // 連線取得資料
        res = URLConnectionUtil.doGet(urlStr,true,"dpssvn01","abcd1234", map);
		SAXReader reader = new SAXReader();
		Document document = reader.read(res);
		Element root = document.getRootElement();

		@SuppressWarnings("unchecked")
		Iterator<Element> it = root.elementIterator();

		while (it.hasNext()) {
			Element e2 = it.next();
			
			if ("job".equalsIgnoreCase( e2.getName() ) ) {
				System.out.println(e2.element("name").getText());	
			}
		}
		
		res.close();
	}
}
